const postModel = require ('../models/postModel')

exports.getAllPost = (req,res) => {
    let obj=req.query;
    postModel.getAllPost(obj,(err,data)=>{
        if(err){
            res.json({
                code:400,
                msg:'获取数据失败'
            })
        }else{
            res.json({
                code:200,
                msg:'获取数据成功',
                data
            })
        }
    })
}

exports.addPost = (req,res)=>{
    // 接收参数
    let obj=req.body
    // obj.in =null
    obj.views = 0
    obj.likes = 0
    obj.user_id = req.session.surrentUser.id
    // 调用数据模块中的方法
    postModel.addPost(obj,(err)=>{
        if(err){
            console.log(err)
            res.json({
                code:400,
                msg:'数据新增失败'
            })
        }else{
            res.json({
                code:200,
                msg:'数据新增成功',
            })
        }
    })
}